<?php

namespace mbilling\BillingBundle\Model;

use Doctrine\ORM\EntityManager;
use mbilling\BillingBundle\Entity\orders;


Class OrderModel
{
    protected $em;

    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }

    public function show($user_id)
    {
        $orders = $this->em->getRepository('BillingBundle:orders')->findBy(array('user_id' => $user_id));
        return $orders;
    }

    public function create($aConfig)
    {    
        $order = new orders();
        $order->setCreatedAt($aConfig['created_at']);
        $order->setDieAt($aConfig['die_at']);
        $order->setIsActive($aConfig['is_active']);
        $order->setType($aConfig['type']);
        $order->setUsername($aConfig['username']);
        $order->setUserId($aConfig['user_id']);

        $this->em->persist($order);
        $this->em->flush();
    }

    public function remove($order_id)
    {
        $order = $this->em->find('BillingBundle:orders', $order_id);
        $this->em->remove($order);
        $this->em->flush();
    } 
}
?>
